package com.feidee.bigdata.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.feidee.bigdata.myhandel.GlobalException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author:CHQ
 * @Date:2020/5/7 18:15
 * @Description
 */
@RestController
public class SentinelController {

    @RequestMapping("/testA")
    @SentinelResource(value = "testA", blockHandlerClass = GlobalException.class, blockHandler = "execptionHandel1")
    public String testA() {
        return "i am testA~~";
    }

    @RequestMapping("/testB")
    public String testB() throws InterruptedException {
        Thread.sleep(1000);
        System.out.println("本次请求线程ID：" + Thread.currentThread().getName());
        return "i am testB~~";
    }

    @RequestMapping("/testC")
    public String testC() throws InterruptedException {
        int a = 10 / 0;
        System.out.println("本次请求线程ID：" + Thread.currentThread().getName());
        return "i am testB~~";
    }

    @RequestMapping("/testHotKey")
    @SentinelResource(value = "testHotKey", blockHandler = "dealTestHotKey")
    public String testHotKey(@RequestParam(value = "p1", required = false) String p1,
                             @RequestParam(value = "p1", required = false) String p2) {
        return "hi i am testHotkey";
    }

    public String dealTestHotKey(String p1, String p2, BlockException blockException) {
        return "呜呜~~~";
    }

}
